<template>
  <div class="PlanManagementDetail">
    <div class="flex location-wrap">
      <span class="white">当前位置：</span>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/EmergencyPlan' }">应急预案</el-breadcrumb-item>
        <el-breadcrumb-item :to="{ path: '/PlanManagement' }">预案管理</el-breadcrumb-item>
        <el-breadcrumb-item>详情</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="main">
      <div class="title">
        <p> {{ DetailList.serialName }}</p>
        <el-button plain size="small" @click="back" class="back">返回</el-button>
      </div>
      <LsdDialogTitle slot="dialog" :titleConfig="titleConfig" :activeNames="activeNames">
        <el-form slot="slot1" ref="form" :model="form" label-width="160px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="应急预案：">
                {{ DetailList.serialName }}
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="预案编号：">
                {{ DetailList.serialNum }}
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="预案体系：">
                {{ DetailList.structureId }}
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="预案类型：">
                {{ DetailList.typeId }}
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="编制部门：">
                {{ DetailList.preplanDepartmentName }}
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="发布单位：">
                {{ DetailList.releaseUnitName }}
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="批准人：">
                {{ DetailList.approver }}
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="发布(修订)时间：">
                {{ releaseTime }}
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="附件：">
                <router-link to="" class="" v-for="(item, index) in accessoryId" :key="index"><span
                    @click="handlePreview(0)">{{ item.attachName }}</span></router-link>
              </el-form-item>
            </el-col>
          </el-row>

        </el-form>
        <el-form slot="slot2" ref="form" :model="form" label-width="160px" inline>
          <el-row>
            <el-col :span="24">
              <el-form-item label="审批材料：">
                <router-link to="" class="" v-for="(item, index) in materialsId" :key="index"><span
                    @click="handlePreview(1)">{{ item.attachName }}</span></router-link>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="备案信息：">
                <router-link to="" class="" v-for="(item, index) in recordsInfoId" :key="index"><span
                    @click="handlePreview(2)">{{ item.attachName }}</span></router-link>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <el-form slot="slot3" ref="form" :model="form" label-width="160px" inline>
          <el-row>
            <el-col :span="8">
              <el-form-item label="创建人：">
                {{ DetailList.creator }}
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="单位及部门：">
                {{ DetailList.createDeptName }}
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="创建时间：">
                {{ DetailList.createTime }}
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </LsdDialogTitle>
    </div>

  </div>
</template>

<script>
import { getByIdApi, getStatisticsApis } from "@/api/EmengercyPlan/yagl";
import { loadFile } from "@/api/common.js";

export default {
  name: "PlanManagementDetail",
  data() {
    return {
      pathId: "",
      titleConfig: [
        {
          title: "基本信息",
          name: "1",
          slot: "slot1"
        },
        {
          title: "审批信息",
          name: "2",
          slot: "slot2"
        },
        {
          title: "创建信息",
          name: "3",
          slot: "slot3"
        }
      ],
      activeNames: ["1", "2", "3"],
      form: {},
      DetailList: {},
      releaseTime: "",
      accessoryId: [],
      materialsId: [],
      recordsInfoId: []
    };
  },
  mounted() {
    this.pathId = JSON.parse(sessionStorage.getItem("id"));
    this.getById();
  },
  methods: {
    back() {
      this.$router.back();
    },
    getById() {
      console.log("route", this.pathId);
      getByIdApi({ id: this.pathId }).then(res => {
        this.DetailList = res;
        this.releaseTime = (res.releaseTime).slice(0, 10);
        this.accessoryId = res.accessoryId;
        this.materialsId = res.materialsId;
        this.recordsInfoId = res.recordsInfoId;
        console.log("getById", res);
        console.log("materialsId", this.materialsId);

      });
    },
    // 下载
    handlePreview(type) {
      // this.$message({
      //   message: "功能开发中",
      //   type: "success"
      // });
      console.log("附件.attachId", this.accessoryId[0]);
      if (type == 0) {
        const loading = this.$loading({
          lock: true,
          text: "Loading",
          spinner: "el-icon-loading",
          background: "rgba(0, 0, 0, 0.6)"
        });

        loadFile({ id: this.accessoryId[0].attachId }).then(res => {
          const a = document.createElement("a");
          const objectUrl = URL.createObjectURL(res);
          a.setAttribute("href", objectUrl);
          a.setAttribute("download", this.accessoryId[0].attachName);
          a.click();
          loading.close();
        }).catch(() => {
          loading.close();
        });
      } else if (type == 1) {
        const loading = this.$loading({
          lock: true,
          text: "Loading",
          spinner: "el-icon-loading",
          background: "rgba(0, 0, 0, 0.6)"
        });

        loadFile({ id: this.materialsId[0].attachId }).then(res => {
          const a = document.createElement("a");
          const objectUrl = URL.createObjectURL(res);
          a.setAttribute("href", objectUrl);
          a.setAttribute("download", this.materialsId[0].attachName);
          a.click();
          loading.close();
        }).catch(() => {
          loading.close();
        });
      } else if (type == 2) {
        const loading = this.$loading({
          lock: true,
          text: "Loading",
          spinner: "el-icon-loading",
          background: "rgba(0, 0, 0, 0.6)"
        });

        loadFile({ id: this.recordsInfoId[0].attachId }).then(res => {
          const a = document.createElement("a");
          const objectUrl = URL.createObjectURL(res);
          a.setAttribute("href", objectUrl);
          a.setAttribute("download", this.recordsInfoId[0].attachName);
          a.click();
          loading.close();
        }).catch(() => {
          loading.close();
        });

      }
      getStatisticsApis({ id: this.pathId, type: 1 }).then(res => {
        console.log(res, "预案下载");
      });
    }
  }
};
</script>

<style lang='less' scoped>
@import "../../../assets/style/common.less";
@import "../../../assets/style/ComponentStyle.less";
@import "../../../assets/style/pop-upNotification.less";

.PlanManagementDetail {
  :deep(.el-breadcrumb__inner.is-link) {
    font-weight: 100;
    font-size: 16px;
    color: #fff;
  }

  :deep(.el-breadcrumb__item:last-child .el-breadcrumb__inner) {
    font-size: 16px;
    color: #3270ff;
  }

  .main {
    height: 100%;
    border-radius: 4px;
    padding: 10px 60px;
    background-color: #fff;
    margin-top: 10px;
    box-sizing: border-box;
    overflow-y: auto;

    .title {
      position: relative;
      text-align: center;
      font-size: 28px;
      color: #303133;
      padding: 20px 0;

      .back {
        position: absolute;
        top: 80px;
        right: 20px;
        padding: 9px 18px;
      }
    }

    :deep(.el-descriptions) {
      font-size: 16px;
    }

    :deep(.desc-label) {
      min-width: 140px;
      justify-content: flex-end;
    }

    :deep(.el-form-item__label),
    :deep(.el-form-item__content) {
      font-size: 16px;
    }

    .link {
      text-decoration: underline;
      color: #3270ff;
      cursor: pointer;
    }
  }
}

:deep(.el-form-item) {
  margin-bottom: 20px;

  .el-form-item__label {
    color: #303133;
  }
}
</style>
